package soccerscope.daistatistic;

import robocup.component.RobocupAgent;
import robocup.component.StateLoader;

/**
 * @author Andr�
 * 
 * this class performs all gui player actions which need an thread (actions
 * which needs more than one cycle)
 */

class Actions {

  // selectors for the action
  public static final int Mode_searchBall  = 2;

  public static final int Mode_goToBall    = 3;

  // pre-define needed variables
  public static double    xPos             = 0;

  public static double    yPos             = 0;

  public static int       power            = 100;

  // flags
  public static boolean   searchBallGoesOn = false;

  public static boolean   goToBall         = false; // continue go to the ball

  public static boolean   runToPos         = false; // continue run to position

  /**
   * main methode, creates selected threads and start them
   * 
   * @param player
   *          the player
   * @param tactic
   *          the player's tactic
   * @param selected
   *          Action/Mode
   */
  public static void start(StateLoader tactic,
      RobocupAgent player,
      int mode) {

    // search Ball selected
    if (mode == Actions.Mode_searchBall) {
      if (!Actions.searchBallGoesOn) {
        ActionSearchBall searchBall = new ActionSearchBall(); // create
        // a new
        // ActionSearchBall
        // class
        searchBall.tactic = tactic; // commit needed values to the class
        searchBall.player = player;
        Actions.searchBallGoesOn = true;
        Thread th = new Thread(searchBall); // create a new thread
        th.start(); // start the thread
      }
      else {
        Actions.searchBallGoesOn = false;
      }

    }

    // go to Ball selected
    if (mode == Actions.Mode_goToBall) {
      if (!Actions.goToBall) {
        ActionGoToBall searchBall = new ActionGoToBall(); // create a
        // new
        // ActionGoToBall
        // class
        searchBall.tactic = tactic; // commit needed values to the class
        Thread th = new Thread(searchBall); // create a new thread
        th.start(); // start the thread
        Actions.goToBall = true; // go to ball is active
      }
      else {
        Actions.goToBall = false; // turn thread off
      }
    }
  }
}

class ActionSearchBall
    implements Runnable {

  public StateLoader  tactic; // committed values

  public RobocupAgent player;

  public void run() {

    while (Actions.searchBallGoesOn) { // while player don't sees the ball
      // do..
      // tactic.searchBall(); //call TacticBean.searchBall
      try {
        Thread.sleep(50); // wait a while for the next move
      }
      catch (Exception e) {
      }
    }
  }
}

class ActionGoToBall
    implements Runnable {

  public StateLoader tactic; // committed value

  public void run() {

    // while ( Actions.goToBall){ //while goToBall = true go to the ball
    // tactic.goToBall(); //call TacticBean.goToBall
    try {
      Thread.sleep(50); // wait a while for the next move
    }
    catch (Exception e) {
    }
    // }
  }
}

/**
 * $Log: Actions.java,v $ Revision 1.2 2006/11/05 13:58:04 wetzker more merging -
 * CLang + MF + some states still missing
 * 
 * Revision 1.1.28.2 2006/07/31 13:36:30 endert Added Java-Doc to constructors
 * if missing, minor refactorings. Revision 1.1.28.1 2006/07/26 15:28:35 endert
 * Formatted Code Revision 1.1 2006/03/13 07:38:28 axle moved from ROOT/src for
 * Maven 2 Buildsystem and Team/Soccerscope separation
 * 
 * Revision 1.3 2006/02/22 16:05:09 endert This is done: - Rebound SoccerScope
 * to Agents (can be added or removed in config-file) - Situations now all
 * extend abstract class Situation - Refactorings: ActionBean _ removed from
 * Attributes - SoccerScope will automatically connect to host given in
 * Start-Call - Trainer uses the same host as soccerscope - Removed unused stuff
 * (old confs, bat, etc.) - Code formatted (good luck when merging) - organized
 * imports - all that i forgot to mention here Revision 1.2 2005/06/15 17:03:31
 * wetzker removed JIAC from Head + changes in framework please report bugs or
 * shortcomings some scenarios might not work because of wrong imports
 * 
 * Revision 1.1.2.1 2005/06/09 12:32:07 endert Removal of JIAC Libraries and
 * dependencies from project, restructuring the framework and improve some
 * aspects (hoping it is an improvement)
 * 
 * Revision 1.1 2005/04/20 10:39:38 endert Fresh Team Repository installation
 * from /home/e/endert/Robocup to here.
 * 
 * Revision 1.3 2005/03/13 14:41:00 haeder - removed unused import
 * 
 * Revision 1.2 2005/02/06 17:47:12 andpaul removed runToPos
 * 
 * Revision 1.1 2005/02/06 17:13:36 andpaul setting up old gui functions for the
 * new gui
 * 
 * Revision 1.2 2005/01/16 21:43:31 andpaul documentation, nothing else
 * 
 * Revision 1.1 2005/01/16 18:02:56 andpaul run threaded actions
 * 
 * 
 * 
 * 
 */
